package com.qf.web.controller;

import com.qf.pojo.PageBean;
import com.qf.pojo.Stu;
import com.qf.service.StuService;
import com.qf.service.impl.StuServiceImpl;
import com.qf.utils.StringUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * projectName:huyi
 * author:jww
 * time:2024/5/2 12:59
 * description:
 */
@WebServlet("/selectstuservlet")
public class SelectUserServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        String pageNum = request.getParameter("pageNum");
        String pageSize = request.getParameter("pageSize");

        int page_num=1;
        int page_size=5;
        try {
            if (!StringUtils.isEmpty(pageNum)) {
                page_num=Integer.parseInt(pageNum);
                if(page_num<1){
                    page_num=1;
                }
            }
            if (!StringUtils.isEmpty(pageSize)) {
                page_size=Integer.parseInt(pageSize);
                if(page_size<1){
                    page_size=5;
                }
            }
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }
        StuService stuService=new StuServiceImpl();
        try {
            PageBean<Stu> pageBean=stuService.findByPage(page_num,page_size);
            request.setAttribute("pageBean",pageBean);
            request.getRequestDispatcher("selectStudent.jsp").forward(request, response);
        } catch (Exception e) {
            e.printStackTrace();
            request.setAttribute("msg", "查询失败" + e.getMessage());
            request.getRequestDispatcher("message.jsp").forward(request, response);
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}


